<?php

/**
 * This is the model class for table "sq_room".
 *
 * The followings are the available columns in table 'sq_room':
 * @property integer $Id
 * @property string $RoomName
 * @property string $Introduce
 * @property integer $RoomType
 * @property integer $UpLimit
 * @property integer $Creator
 * @property integer $Created
 * @property string $RoomFirstName
 * @property integer $RoomPri
 * @property integer $Commend
 * @property integer $RoomIsShow
 */
class Room extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Room the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'sq_room';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('RoomType, UpLimit, Creator, Created, RoomPri, Commend, RoomIsShow', 'numerical', 'integerOnly'=>true),
			array('RoomName,RoomFirstName,Introduce,Creator,Commend','required'),
			array('RoomName', 'length','min'=>2, 'max'=>100),
			array('RoomFirstName', 'length', 'max'=>10),
			array('Introduce', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('Id, RoomName, Introduce, RoomType, UpLimit, Creator, Created, RoomFirstName, RoomPri, Commend, RoomIsShow', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
				'roomowner'=>array(self::BELONGS_TO, 'Userinfo', 'Id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'Id' => 'ID',
			'RoomName' => '房间名',
			'Introduce' => '房间简介',
			'RoomType' => '房间类型',
			'UpLimit' => '人数上限',
			'Creator' => '创建者',
			'Created' => '创建时间',
			'RoomFirstName' => '房间首字',
			'RoomPri' => '房间权限',
			'Commend' => '推荐值',
			'RoomIsShow' => '是否展现',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('Id',$this->Id);
		$criteria->compare('RoomName',$this->RoomName,true);
		$criteria->compare('Introduce',$this->Introduce,true);
		$criteria->compare('RoomType',$this->RoomType);
		$criteria->compare('UpLimit',$this->UpLimit);
		$criteria->compare('Creator',$this->Creator);
		$criteria->compare('Created',$this->Created);
		$criteria->compare('RoomFirstName',$this->RoomFirstName,true);
		$criteria->compare('RoomPri',$this->RoomPri);
		$criteria->compare('Commend',$this->Commend);
		$criteria->compare('RoomIsShow',$this->RoomIsShow);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}